/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JPanelColaboracion2.java
 *
 * Created on 19-may-2010, 19:12:44
 */

package edu.ieslaferreria.creditsintesis.builders.Swing;


import edu.ieslaferreria.creditsintesis.rmi.Client;
import edu.ieslaferreria.creditsintesis.rmi.EventChangePanel;
import edu.ieslaferreria.creditsintesis.rmi.EventIniciarInteraccion;
import edu.ieslaferreria.creditsintesis.rmi.EventPanelsInteractionTwoPlayersListener;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;


/**
 *
 * @author Administrador
 */
public class JPanelInicio_1 extends JPanelGame {
private int Option;
  
     
 private EventIniciarInteraccion listenerComp1;
    private EventPanelsInteractionTwoPlayersListener listenerComunicationOtherPanel;

    /** Creates new form JPanelColaboracion2 */
    public JPanelInicio_1(Client client) {
        initComponents();
        this.setClient(client);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBoxAccionesIniciales = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jButtonEnviar = new javax.swing.JButton();

        jComboBoxAccionesIniciales.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel1.setText("Acciones iniciales disponibles");

        jButtonEnviar.setText("Enviar");
        jButtonEnviar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEnviarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(80, 80, 80)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jComboBoxAccionesIniciales, javax.swing.GroupLayout.PREFERRED_SIZE, 410, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(242, 242, 242)
                        .addComponent(jButtonEnviar)))
                .addContainerGap(94, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(32, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(27, 27, 27)
                .addComponent(jComboBoxAccionesIniciales, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(45, 45, 45)
                .addComponent(jButtonEnviar)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonEnviarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEnviarActionPerformed
        /*aixeca event de comunicacio per que l'altre panell reaccioni*/
        try {

            this.Option= jComboBoxAccionesIniciales.getSelectedIndex() ;

/*meto cliente en un arraylist...los eventos tienen arraylist, quizas seria bastante un string*/
            ArrayList<String> alias = new ArrayList();
            alias.add(getClient().getNom());


             /*envio el canvio a mi mismo con boolean de respuesta a false*/
//            client.send(new EventChangePanel(null,Option,false,alias,pontPanel));
        getClient().onMessage(new EventChangePanel(null,Option,false,alias,getPontPanel()));
   /*envio por el puente de la partida a todos los players de susodicha menos yo,
   * enviando mi nombre para que sepan a quien NO debe enviarselo*/
            this.getPontPanel().send(new EventChangePanel(null,Option+6,false,alias,getPontPanel()));
        } catch (RemoteException ex) {
            Logger.getLogger(JPanelCompetition2.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_jButtonEnviarActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonEnviar;
    private javax.swing.JComboBox jComboBoxAccionesIniciales;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables

    public void update(Map<String, List<String>> opcions,ArrayList<String> extras) {

        this.jComboBoxAccionesIniciales.setModel(new DefaultComboBoxModel(opcions.get(OPCIO_BASICA).toArray()));
    }

   
    /**
     * @return the listenerComp1
     */
    public EventIniciarInteraccion getListenerComp1() {
        return listenerComp1;
    }

    /**
     * @param listenerComp1 the listenerComp1 to set
     */
    public void setListenerComp1(EventIniciarInteraccion listenerComp1) {
        this.listenerComp1 = listenerComp1;
    }

    /**
     * @return the listenerComunicationOtherPanel
     */
    public EventPanelsInteractionTwoPlayersListener getListenerComunicationOtherPanel() {
        return listenerComunicationOtherPanel;
    }

    /**
     * @param listenerComunicationOtherPanel the listenerComunicationOtherPanel to set
     */
    public void setListenerComunicationOtherPanel(EventPanelsInteractionTwoPlayersListener listenerComunicationOtherPanel) {
        this.listenerComunicationOtherPanel = listenerComunicationOtherPanel;
    }


}
